package com.jincheng.web;

import com.jincheng.pojo.Auctionuser;
import com.jincheng.service.AuctionuserService;
import com.jincheng.utils.R;
import my.framework.anno.RequestMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Jane
 * @date 2024-12-13 10:43
 */

public class AuctionUserController  {
    AuctionuserService auctionuserService = null;

    public AuctionUserController(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("auctionUserApplication.xml");
        this.auctionuserService = (AuctionuserService) ctx.getBean("auctionuserService");// new AuctionuserServiceImpl();
    }
    @RequestMapping("/login")
    public Object login(HttpServletRequest request, HttpServletResponse response){
        System.out.println("user - login");

        try {
            Auctionuser user = auctionuserService.login(request.getParameter("username")
                    ,request.getParameter("password"));
            if (null!=user){
                System.out.println("ok");
                //跳转
                //数据存session
                request.getSession().setAttribute("loginUser",user);
                //转发   可以传递数据
               // request.getRequestDispatcher("auctionList.jsp").forward(request,response);
                return "forward:/index.jsp";
            }else{
                System.out.println("error");
                //重定向  丢失数据
//                response.sendRedirect("login.jsp");
                return "redirect:/login.jsp";
            }
        } catch (Exception e) {
            //e.printStackTrace();
            System.out.println("error"+e.getMessage());
//            R.ok()
//            R.fail()
            return R.fail().data(e.getMessage());

        }

    }

    @RequestMapping("/user/userList")
    public void userList(){

    }
    @RequestMapping("/user/regiest")
    public void regiest(){

    }
    @RequestMapping("/user/updatePassword")
    public void updatePassword(){

    }
}
